package com.aaa.hospital.service.impl;

import com.aaa.hospital.mapper.PatientMapper;
import com.aaa.hospital.pojo.domain.*;
import com.aaa.hospital.pojo.query.JianyiQuery;
import com.aaa.hospital.pojo.query.PatientQuery;
import com.aaa.hospital.pojo.query.YuyueQuery;
import com.aaa.hospital.pojo.vo.AddProposal;
import com.aaa.hospital.result.AjaxResult;
import com.aaa.hospital.service.PatientService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;

/**
 * Author:张海金
 * Description:T0D0
 * DateTime:2022/1/15 19:10
 **/
@Service
public class PatientServiceImpl implements PatientService {
    @Autowired
    private PatientMapper patientMapper;

    @Override
    public AjaxResult queryPatient(PatientQuery query) {
        // 查询当前页的病人预约信息
        List<Patient> patients = patientMapper.queryPatient(query);
        //查询符合条件的总数量
        Long aLong = patientMapper.queryPatientTotal(query);

        //把查询的预约信息和总数量 放到Map里返回
        HashMap<Object, Object> objectObjectHashMap = new HashMap<>();
        objectObjectHashMap.put("currentData",patients);
        objectObjectHashMap.put("totalCountt",aLong);

        return AjaxResult.success(objectObjectHashMap);
    }

    @Override
    public AjaxResult get(Integer id) {

        // 管理员点击接受预约，获取点击行的ID，根据ID修改病人的state状态
        int i =  patientMapper.updatestate(id);

        //修改完状态之后然后根据id查询当前数据
        List<Patient> patients =  patientMapper.getId(id);

        //拿到查询的数据然后添加到预约表里面
//        int a = patientMapper.addyuyue(patients);

        return AjaxResult.success();
    }


    @Override
    public AjaxResult list(YuyueQuery yuyueQuery) {
        // 查询已预约上的病人
        List<Yuyue> yuyues = patientMapper.list(yuyueQuery);
        Long along = patientMapper.querylistTotal(yuyueQuery);

        HashMap<Object, Object> listyuyue = new HashMap<>();
        listyuyue.put("allyuyue",yuyues);
        listyuyue.put("allyuyuetotal",along);

        return AjaxResult.success(listyuyue);
    }

    @Override
    public AjaxResult query(Integer id) {
        Yuyue data = patientMapper.query(id);

        return AjaxResult.success(data);
    }

    @Override
    public AjaxResult add(AddProposal proposal) {

        int i = patientMapper.add(proposal);

        Integer id = proposal.getId();

        int a = patientMapper.setState(id);
        return AjaxResult.success(i);
    }



    @Override
    public AjaxResult queryAll(JianyiQuery patient) {

        //查询当前页信息
        List<Jianyi> jianyis = patientMapper.queryAll(patient);
        //查询符合条件的总数量
        Long aLong = patientMapper.queryAllTotal(patient);

        HashMap<Object, Object> data = new HashMap<>();
        data.put("jianyiData",jianyis);

        data.put("patientCount",aLong);

        return AjaxResult.success(data);
    }

    @Override
    public AjaxResult setrefuse(Integer id) {
        System.out.println("========" + id + "==========");
        int i = patientMapper.setrefuse(id);
        return AjaxResult.success();
    }

    @Override
    public AjaxResult remove(Integer id) {
        int i = patientMapper.remove(id);
        if ( i>0 ){
            return AjaxResult.success();
        }else {
            return AjaxResult.fail();
        }
    }

    @Override
    public AjaxResult getResult(String a) {
        // 拿到用户昵称
        Signin signin = patientMapper.getNickname(a);
        String name = signin.getNickname();

        Patient patient = patientMapper.getPatient(name);
        System.out.println("输出病人全部信息" + patient);
        return AjaxResult.success(patient);
    }

    @Override
    public AjaxResult getProposal(String name) {
        Jianyi jianyi = patientMapper.getProposal(name);
        return AjaxResult.success(jianyi);
    }


}
